package com.example.mobile2021606127cxz0420;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class CarAdapter extends RecyclerView.Adapter<CarAdapter.MyViewHolder> {
    private int[] photo;
    private String[] text;

    public CarAdapter(int[] photo, String[] text) {
        this.photo = photo;
        this.text = text;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items_car, null);
//        MyViewHolder viewHolder = new MyViewHolder(view);
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.items_car,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.imageView.setImageResource(photo[position]);
        holder.textView.setText(text[position]);
    }

    @Override
    public int getItemCount() {
        return photo.length & text.length;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imageView);
            textView = itemView.findViewById(R.id.textView);
        }
    }
}
